<!DOCTYPE html>
<meta charset="UTF-8">
<!-- based on crbug.com/94895#c20
     http://crbug.com/94895
     http://webkit.org/b/76461 -->
<script>
if (location.search != '?reenter') {
  if (window.testRunner) {
    testRunner.dumpAsText();
    testRunner.waitUntilDone();
  }

  webkitRequestFileSystem(TEMPORARY, 1024*1024,
                          gotFS, onError.bind(null, 'requestFileSystem'));
} else {
  document.write('PASS');

  if (window.testRunner)
    testRunner.notifyDone();
}

function onError(msg, e) {
  document.body.innerText = 'FAIL: ' + e.name + ' msg = ' + msg;
  if (window.testRunner)
    testRunner.notifyDone();
}

function gotFS(fs) {
  fs.root.getFile('hoge', {create: true},
                  gotEntry, onError.bind(null, 'getFile'));
}

function gotEntry(entry) {
  // It should not cause a crash that calling FileEntry.file() while the page is unloading.
  location.search = '?reenter';
  entry.file(gotFile, onError.bind(null, 'file'));
}

function gotFile(file) {
  // Ignore the result of FileEntry.file().
}
</script>
